package com.caiwangdai.app.origin

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.caiwangdai.app.R
import com.caiwangdai.app.extension.inflate
import com.caiwangdai.app.origin.back.BackHandlerHelper
import com.caiwangdai.app.origin.back.FragmentBackHandler
import com.orhanobut.logger.Logger

/**
 * @project KotLinProject
 * @author 艹羊
 * @date 2017/6/9 下午5:54
 * @description
 */
abstract class BaseFragment : Fragment(), FragmentBackHandler {
    lateinit var mActivity: BaseActivity
    lateinit var WMContent: ViewGroup

    /**
     * 获得全局的，防止使用getActivity()为空
     */
    override fun onAttach(context: Context?) {
        super.onAttach(context)
        mActivity = context as BaseActivity
    }

    /**
     * 该抽象方法就是 onCreateView中需要的layoutID
     */
    protected abstract fun getLayoutId(): Int


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        WMContent = container?.inflate(getLayoutId()) as ViewGroup
        return WMContent
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        initData()
        initView()
    }


    open fun initData() {}

    open fun initView() {}


    override fun onBackPressed(): Boolean {
        return BackHandlerHelper.handleBackPress(this)
    }
}


